package com.daocao.ds.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.daocao.ds.R;
import com.daocao.ds.api.model.LoanerLogsModel;
import com.daocao.ds.util.DateTime;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class TransactionRecordAdapter extends ItemAdapter<LoanerLogsModel.DatasBean, TransactionRecordAdapter.DefaultHolder> {


    private Context context;

    public TransactionRecordAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_transaction_record, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        LoanerLogsModel.DatasBean item = getItem(position);
        holder.txtName.setText(item.name);
        holder.txtNameSec.setText("[备注：" + item.memo + "]");
        holder.txtMoney.setText(item.money);
        if (item.money.contains("-")) {
            holder.txtMoney.setTextColor(0xff333333);
        } else {
            holder.txtMoney.setTextColor(0xff0072FF);
        }
        holder.txtTime.setText(DateTime.toDateTime(Long.valueOf(item.created_at) * 1000));
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_icon)
        CircleImageView imgIcon;
        @BindView(R.id.txt_name)
        TextView txtName;
        @BindView(R.id.txt_name_sec)
        TextView txtNameSec;
        @BindView(R.id.txt_time)
        TextView txtTime;
        @BindView(R.id.txt_money)
        TextView txtMoney;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onSuccess();
    }
}
